package run;

import java.io.File;
import java.util.ArrayList;

import outils.Parser;

/**
 * 
 */

/**
 * @author alith
 *
 */
public class Launcher {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		if (args.length != 1) {
			System.out.println(" usage: java Launcher <path du fichier de test>");
		} else {
			ArrayList<Executable> executables = new ArrayList<Executable>();
			ArrayList<Integer> numerosEchec = new ArrayList<Integer>();
			executables.addAll(Parser.parse(new File(args[0])));
			for (int i =0; i< executables.size();i++) {
				ResultatExecution result = executables.get(i).execute();
				if (!result.success()){
					numerosEchec.add(i);
				}
				System.out.println("**** commande n°"+(i+1)+"****");
				System.out.println(result);
			}
			System.out.println("*****  BILAN  *****");
			System.out.println("le nombre de commande executées sans succes au total est: " + numerosEchec.size() + "/" + executables.size());
			if (!numerosEchec.isEmpty()) System.out.println("les commandes ayant rencontré des erreurs sont: ");
			for (int i= 0; i<numerosEchec.size(); i++){
				System.out.println("la commande n°"+ (numerosEchec.get(i)+1));
			}
		}
	}

}
